﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using Portal.Systems.Model;
using Portal.Core;
using System.Collections.ObjectModel;

namespace Portal.Systems.Bussiness.Template
{
    public interface ISystemsBussinessProcess
    {
        string ServiceId { get; }
        
        AccountTypeCls[] ReadingAccountType(string SiteId,string ParentAccountType);
        AccountTypeCls CreateAccountTypeModel(string SiteId, string AccountType);
        void AddAccountType(
            string SiteId,
            string ParentAccountType,
            string AccountType,
            string Description);
            

        void SaveAccountType(string SiteId, string AccountType, string Description);
        void DeleteAccountType(string SiteId, string AccountType);

        void MoveRoleToAccountType(string SiteId, string[] AccountTypes, string RoleId);
        
        //*************************************************************************

        SystemLogCls[] ReadingSystemLog(
         string SiteId,
         string FromDate,
         string ToDate);

        UserNotLoginCls[] ReadingUserNotLogin(
            string SiteId,
            int Month);

        void AddSysLogProcess(
             string SiteId,
             string AssetCode,
             string Action,
             string ActionText,
             string UserId,
             string LoginName,
             string FullName);

        void Delete(
             string SiteId,
             string[] Ids);
        //*************************************************************************

        void InitPermisison(string SiteId, IPermission OPermissionTemplate);

        PermissionRoleCls[] ReadingPermissionRoles(
            string SiteId,
            string PermissionTypeId,
            string ObjectId);

        string[] ReadingPermissionFunction(
            string SiteId,
            string PermissionTypeId);

        PermissionRoleDetailCls[] ReadingPermissionRoleDetail(
            string SiteId,
            string PermissionTypeId,
            string PermissionRoleId);

        void InitPermissionRoleDetail(
            IDbTransaction Trans,
            string SiteId,
            string PermissionTypeId,
            string PermissionRoleId);

        RoleCls[] ReadingRoleForPermission(
            string SiteId,
            string PermissionTypeId,
            string ObjectId,
            string AccountType,
            string Keyword);

        UserCls[] ReadingUserForPermission(
            string SiteId,
            string PermissionTypeId,
            string ObjectId,
            string AccountType,
            string Keyword);

        void AddRolePermission(
            string SiteId,
            string ptc,
            string ObjectId,
            string[] RoleIds,
            string[] UserIds);

        PermissionRoleCls CreatePermissionRoleModel(
           string SiteId,
           string PermissionRoleId);

        void DeleteNotExistsInObject(string SiteId, string PermissionTypeId);

        void SetPermissionDetail(
            string SiteId,
            string PermissionRoleId,
            string[] PermissionDetailIds);

        void DeletePermissionRole(
            string SiteId,
            string PermissionRoleId);

        bool CheckPermission(
            string SiteId,
            string ptc,
            string PermissionFunctionId,
            string ObjectId,
            string UserId,
            bool ThrowException);


        //*******************************
        RoleCls[] ReadingRoles(string SiteId, string RoleType, string Keyword);

        RoleCls[] ReadingRolesForDatabaseFolderPermission(
            string SiteId, 
            string DatabaseFolderId,
            string Keyword);

        UserCls[] ReadingUserForDatabaseFolderPermission(
            string SiteId,
            string DatabaseFolderId,
            string Keyword);


        RoleCls[] ReadingRolesForDatabaseFieldPermission(
            string SiteId,
            string DatabaseFieldId,
            string Keyword);

        UserCls[] ReadingUserForDatabaseFieldPermission(
            string SiteId,
            string DatabaseFieldId,
            string Keyword);

        RoleCls CreateRoleModel(string SiteId, string RoleId);
        string AddRole(
            IDbTransaction Trans,
            string SiteId,
            string AssetCode,
            string RoleId,
            string RoleCode,
            string RoleName,
            string RoleType);
        void SaveRole(IDbTransaction Trans, string SiteId, string RoleId, string LoginName, string FullName);
        void DeleteRole(IDbTransaction Trans, string SiteId, string RoleId);
        RoleCls[] ReadingRolesForUser(string SiteId, string UserId);






        //*******************************
        GroupRoleCls[] ReadingGroupRoles(string SiteId, string Keyword);
        GroupRoleCls CreateGroupRoleModel(string SiteId, string GroupRoleId);
        string AddGroupRole(
            IDbTransaction Trans,
            string SiteId,
            string AssetCode,
            string GroupRoleId,
            string GroupRoleName,
            int    SortIndex);
        void SaveGroupRole(IDbTransaction Trans, string SiteId, string GroupRoleId, string GroupRoleName, int SortIndex);
        void DeleteGroupRole(IDbTransaction Trans, string SiteId, string GroupRoleId);
        RoleCls[] ReadingRoleForGroupRole(string SiteId, string GroupRoleId);
        RoleCls[] ReadingRoleAvailableForGroupRole(string SiteId, string GroupRoleId, string Keyword);
        RoleCls[] ReadingRoleBelongGroupRole(string SiteId, string GroupRoleId, string Keyword);
        void AddRoleToGroupRole(IDbTransaction Trans, string SiteId, string GroupRoleId, string RoleId);
        void RemoveRoleFromGroupRole(IDbTransaction Trans, string SiteId, string RoleInGroupRoleId);
        void RemoveRoleFromGroupRole(IDbTransaction Trans, string SiteId, string GroupRoleId,string RoleId);




        //************************************
        UserCls[] ReadingUsers(string SiteId, string RoleId, string Keyword);
        UserCls[] ReadingAvailableUser(string SiteId, string RoleId, string Keyword);
        UserCls[] ReadingUserBelongRole(string SiteId, string RoleId, string Keyword);
        Collection<UserCls> ReadingUserBelongRoleForWorkflow(string SiteId, string[] RoleIds);

        UserCls CreateUserModel(string SiteId, string UserId);
        UserCls CheckHasUser(string SiteId, string AssetCode,string LoginName);

        void AddUser(
            IDbTransaction Trans,
            string SiteId,
            string AssetCode,
            string UserId,
            string LoginName,
            string FullName,
            string Email,
            string Password,
            string ReTypePassword,
            string[] RoleIds,
            bool   CheckValid);
        void AddUserToRole(
            IDbTransaction Trans,
            string SiteId,
            string RoleId,
            string UserId);
        void RemoveUserFromRole(
            IDbTransaction Trans,
            string SiteId,
            string RoleId,
            string UserId);

        void SaveUser(IDbTransaction Trans, string SiteId, string StudentId, string LoginName, string FullName, string RoleId);

        

        void DeleteUser(IDbTransaction Trans, string SiteId, string UserId);
        void BlockUser(IDbTransaction Trans, string SiteId, string UserId, int LockVal);
        void ChangePassword(string SiteId, string AssetCode,string LoginName, string Password, string RePassword);
        UserCls CheckForLogin(string SiteId, string AssetCode, string LoginName, string Password, ref int LoginAttempCount, ref string gLoginName);
        

        AssetCls[] ReadingAssets(string SiteId);
        AssetCls CreateAssetModel(string SiteId, string AssetCode);

        
        UserQuickLinkCls CreateUserQuickLinkModel(string SiteId, string UserQuickLinkId);
        void AddUserQuickLink(string SiteId, UserQuickLinkCls OUserQuickLink);
        void DeleteUserQuickLink(string SiteId,string UserQuickLinkId);
        UserQuickLinkCls[] ReadingUserQuickLinks(string SiteId, string UserId);


        BackSessionCls CreateBackSessionModel(string SiteId, string BackSessionId);
        void AddBackSession(string SiteId, BackSessionCls OBackSession);
        void DeleteBackSession(string SiteId, string BackSessionId);
        BackSessionCls[] ReadingBackSessions(string SiteId, string UserId);

        RoleMenuCls CreateRoleMenuModel(string SiteId, string RoleMenuId);
        void SaveRoleMenu(string SiteId, string AssetCode, string RoleId, RoleMenuCls[] ORoleMenu);
        void DeleteRoleMenu(string SiteId, string RoleMenuId);
        RoleMenuCls[] ReadingRoleMenus(string SiteId, string RoleId);

        void SyncRoleAndUsers(string SiteId, RoleCls[] Roles);



        //WebPage
        PageCls CreatePageModel(string SiteId, string PageId);
        PageCls[] ReadingPage(string SiteId,string Keyword);
        void AddPage(string SiteId, PageCls OPage);
        void SavePage(string SiteId, string PageId,PageCls OPage);
        void DeletePage(string SiteId, string PageId);
        void PublishingPage(string SiteId, string PageId);
        void UnPublishingPage(string SiteId, string PageId);
        void DeployPage(string SiteId, string PageId);
        void UnDeployPage(string SiteId, string PageId);

        //webpage-zone
        PageZoneCls CreatePageZoneModel(string SiteId, string PageZoneId);
        PageZoneCls[] ReadingPageZone(string SiteId, string PageId, string Keyword);
        void AddPageZone(string SiteId, PageZoneCls OPageZone);
        void SavePageZone(string SiteId, string PageZoneId, PageZoneCls OPageZone);
        void DeletePageZone(string SiteId, string PageZoneId);
        void PublishingPageZone(string SiteId, string PageZoneId);
        void UnPublishingPageZone(string SiteId, string PageZoneId);

        //webpage-zone-module
        PageZoneModuleCls CreatePageZoneModuleModel(string SiteId, string PageZoneModuleId);
        PageZoneModuleCls[] ReadingPageZoneModule(string SiteId, string PageZoneId);
        PageZoneModuleCls[] ReadingModulesInPage(string SiteId, string PageId);

        void AddPageZoneModule(string SiteId, PageZoneModuleCls OPageZoneModule);
        void SavePageZoneModule(string SiteId, string PageZoneModuleId, PageZoneModuleCls OPageZoneModule);
        void SavePageZoneModuleConfig(string SiteId, string PageZoneModuleId, string XmlDataConfig);
        void DeletePageZoneModule(string SiteId, string PageZoneModuleId);
        void PublishingPageZoneModule(string SiteId, string PageZoneModuleId);
        void UnPublishingPageZoneModule(string SiteId, string PageZoneModuleId);
        void SavePageZoneModuleView(string SiteId, string PageZoneModuleId, string PlugInViewId);
        void SavePageZoneForMove(string SiteId, string PageZoneModuleId, string PageZoneId);
        void SavePageZoneModuleInfo(string SiteId, PageZoneModuleCls[] PageZoneModules);

        WorkflowDefCls CreateWorkflowDefModel(string SiteId, string WorkflowDefId);
        WorkflowDefCls[] ReadingWorkflowDef(string SiteId);

        WorkflowDefMapRoleCls[] ReadingWorkflowDefMapRoles(string SiteId, string WorkflowDefId, RoleCls[] WorkflowRoles);
        void SaveWorkflowDefMapRoles(string SiteId,string WorkflowDefId, WorkflowDefMapRoleCls[] WorkflowDefMapRoles);

        //WorkflowControl
        WorkflowControlCls[] ReadingWorkflowControls(string SiteId);
        void SaveWorkflowControls(string SiteId,WorkflowControlCls[] WorkflowControls);
        WorkflowDefCls CreateWorkflowDefFromWorkflowControl(string SiteId, string WorkflowControlId);
        WorkflowControlCls CreateWorkflowControlModel(string SiteId, string WorkflowControlId);

        DataLanguageCls[] ReadingDataLanguage(string SiteId);
        DataLanguageCls CreateDataLanguageModel(string SiteId,string DataLanguageId);

        RoleExtraConfigCls CreateRoleExtraConfigModel(string SiteId, string RoleExtraConfigId);
        RoleExtraConfigCls CreateRoleExtraConfigModel(string SiteId, string AssetCode, string RoleId, string DataLanguageId);
        void SaveRoleExtraConfig(
            string SiteId,
            string RoleId,
            string DataLanguageId,
            RoleExtraConfigCls ORoleExtraConfig);

        RoleWorkingWorkflowCls[] ReadingRoleWorkingWorkflow(string SiteId, string RoleId);
        RoleWorkingWorkflowCls[] ReadingAllowAccessRoleWorkingWorkflow(string SiteId, string RoleId);
        RoleWorkingWorkflowCls[] ReadingAllowAccessRoleWorkingWorkflow(string SiteId, string RoleId,string WorkflowControlType);

        bool CheckAllowAccessWorkflow(string SiteId, string RoleId, string WorkflowDefId);
        void SaveRoleWorkingWorkflow(string SiteId, string RoleId, RoleWorkingWorkflowCls[] RoleWorkingWorkflow);
        RoleWorkingWorkflowCls CreateRoleWorkingWorkflowModel(string SiteId, string RoleWorkingWorkflowId);
        Collection<UserCls> ReadingUsersInGroupRoles(string SiteId, string[] GroupRoleIds);
        string[] ConvertSystemGroupRoleFromWorkflowGroupRole(string SiteId, string WorkflowDefId, string[] GroupRoleIds);

        //Role Relation Template
        RoleRelationTemplateCls[] ReadingRoleRelationTemplate(string SiteId, string Keyword);
        RoleRelationTemplateCls CreateRoleRelationTemplateModel(string SiteId, string RoleRelationTemplate);
        void AddRoleRelationTemplate(
            IDbTransaction Trans,
            string SiteId,
            string AssetCode,
            string RoleRelationTemplateName,
            int SortIndex,
            string XmlData);

        void SaveRoleRelationTemplate(
            IDbTransaction Trans,
            string SiteId,
            string RoleRelationTemplateId,
            string RoleRelationTemplateName,
            string XmlData);
        void DeleteRoleRelationTemplate(IDbTransaction Trans, string SiteId, string RoleRelationTemplateId);



        void SaveArchiveTempFile(IDbTransaction Trans, string SiteId, string ArchiveTempFileId, string SaveFile, string SaveTitle);
        void DeleteArchiveTempFile(IDbTransaction Trans, string SiteId, string ArchiveTempFileId);

        AccountTypeCls[] ReadingAccountTypeForRole(string SiteId,  string RoleId);
        string DuplicatePage(string SiteId, string PageId);
    }
}

